/**
 * @Author: Gongxh
 * @Date: 2025-07-19
 * @Description: 
 */

import { Color, Enum, Size, Vec2, Vec3 } from 'cc';
import { _ecsdecorator } from 'db://kunpo-ec/ECSDecorator';

const { ecsclass, ecsprop } = _ecsdecorator;

/** 基础属性示例 */
@ecsclass("BaseComponent", { describe: "基础组件" })
export class BaseComponent {
    @ecsprop({ type: "int", defaultValue: 0, displayName: "血量" })
    hp: number = 0;

    @ecsprop({ type: 'float', defaultValue: 0, displayName: "最大血量" })
    maxHp: number = 0;

    @ecsprop({ type: 'string', defaultValue: "", displayName: "字符串" })
    string: string = "";

    @ecsprop({ type: 'boolean', defaultValue: false, displayName: "布尔值" })
    bool: boolean = true;
}

/** 单层复合属性示例 */
enum HealthType {
    One = 1,
    Two = 2,
    Three = 3
}

@ecsclass("CompositeComponent", { describe: "复合属性组件" })
export class CompositeComponent {
    @ecsprop({ type: "enum", format: Enum(HealthType), defaultValue: HealthType.One, displayName: "枚举" })
    hpeunm: HealthType = HealthType.One;

    @ecsprop({ type: "array", format: "entity", displayName: "单层数组" })
    list: string[] = [];

    @ecsprop({ type: "array", format: "int" })
    arr: number[];

    @ecsprop({ type: "vec2", displayName: "向量2" })
    vec2: Vec2;

    @ecsprop({ type: "vec3", displayName: "向量3" })
    vec3: Vec3;

    @ecsprop({ type: "color", defaultValue: Color.RED, displayName: "颜色" })
    color: Color;

    @ecsprop({ type: "size", displayName: "尺寸" })
    size: Size;
}

/** 多层嵌套复合属性示例 */
@ecsclass("MultiNestedCompositeComponent", { describe: "多层嵌套复合属性组件" })
export class MultiNestedCompositeComponent {

    @ecsprop({
        type: "array", format: { type: "object", format: { hp: "int", max: "int" } }
    })
    arrobj: { hp: number, max: number }[] = [];

    /** 写起来会比较复杂 */
    @ecsprop({
        type: "object", format: {
            hp1: {
                type: "object",
                format: {
                    hp: "int",
                    max: "int"
                }
            },
            hp2: {
                type: "object",
                format: {
                    hp: "int",
                    max: "int"
                }
            },
        },
    })
    obj: { hp1: { hp: number, max: number }, hp2: { hp: number, max: number } };
}


@ecsclass("AssetComponent", { describe: "资源组件" })
export class AssetComponent {

    // 编辑器中配置的实体 也可以拖拽引用，导出后是实体名
    @ecsprop({ type: "entity", defaultValue: "", displayName: "实体", tips: "实体" })
    entityName: string = "";

    // cc中的资源类型 导出后是资源的uuid

    @ecsprop({ type: "spriteframe", displayName: "精灵帧" })
    spriteFrame: string = "";

    @ecsprop({ type: "asset", displayName: "资源" })
    asset: string = "";

    @ecsprop({ type: "prefab", displayName: "预制体" })
    prefab: string = "";

    @ecsprop({ type: "skeleton", displayName: "骨骼动画" })
    skeleton: string = "";

    @ecsprop({ type: "particle", displayName: "粒子" })
    particle: string = "";

    @ecsprop({ type: "animation", displayName: "动画" })
    animation: string = "";

    @ecsprop("audio", { type: "audio", displayName: "音频" })
    audio: string = "";

    @ecsprop("jsonAsset", { type: "jsonAsset", displayName: "json资源" })
    jsonAsset: string = "";
}